package models.re.realData;

import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.ManyToOne;
import javax.persistence.Query;

import play.db.jpa.JPA;

import models.aaa.Asset;
import models.aaa.Node;
import models.re.IItem;
import models.re.ISimilarity;

@Entity
public class AssetSimilarity extends Node implements ISimilarity {
	
	private Double value = 0.0;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Asset source = null;
	
	@ManyToOne(fetch=FetchType.LAZY)
	private Asset target = null;
	
	AssetSimilarity() {
		
	}
	
	AssetSimilarity(IItem source, IItem target, Double value) {
		this.source=(Asset)source;
        this.target=(Asset)target;  
        this.value=value;
	}
	
	public static AssetSimilarity findById(Long id) {
		return JPA.em().find(AssetSimilarity.class, id);
	}
	
	public static void purge() {
		String sql = "DELETE FROM AssetSimilarity";
        Query query = JPA.em().createQuery(sql);
        query.executeUpdate();
	}

	@Override
	public Double getValue() {
		// TODO Auto-generated method stub
		return this.value;
	}	

	@Override
	public IItem getSource() {
		// TODO Auto-generated method stub
		return this.source;
	}

	@Override
	public IItem getTarget() {
		// TODO Auto-generated method stub
		return this.target;
	}

}
